import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
import { message, ConfigProvider } from 'antd';
import zhCN from 'antd/es/locale/zh_CN';
import { BrowserRouter } from 'react-router-dom' //两种路由模式，BrowserRouter和HashRouter模式，类似vue的history模式和hash模式。react中一般使用BrowserRouter模式
import store from './redux/store';
import { Provider } from 'react-redux';

//全局消息提示配置
message.config({
  duration: 2,
  maxCount: 1
});

const root = ReactDOM.createRoot(document.getElementById('root'));
const rootRender = () => {
  root.render(
    // React.StrictMode 组件用于检查APP组件中是否写了，官方不推荐的写法，并抛出警告。并且会将组件有意的 render两次。
    <BrowserRouter>
      <React.StrictMode>
        <ConfigProvider locale={zhCN}>
          {/* 利用react-redux模型的Provider组件，给App组件注入redux的状态 */}
          <Provider store={store}>
            <App />
          </Provider>
        </ConfigProvider>
      </React.StrictMode>
    </BrowserRouter>
  );
}

rootRender();
store.subscribe(() => rootRender())  //如果没有使用react-redux模型，就需要手动使用redux的subscribe方法监听状态变化。(本项目中因为SimpleCounter组件未使用react-redux模型，所以需开启)

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();
